<?php

use yii\db\Migration;

/**
 * Handles adding columns to table `{{%page}}`.
 * Has foreign keys to the tables:
 *
 * - `{{%site}}`
 */
class m231123_130049_add_id_site_column_to_page_table extends Migration
{
    /**
     * {@inheritdoc}
     */
    public function safeUp()
    {
        $this->addColumn('{{%page}}', 'id_site', $this->integer()->notNull()->defaultValue(1));

        // creates index for column `id_site`
        $this->createIndex(
            '{{%idx-page-id_site}}',
            '{{%page}}',
            'id_site'
        );

        // add foreign key for table `{{%site}}`
        $this->addForeignKey(
            '{{%fk-page-id_site}}',
            '{{%page}}',
            'id_site',
            '{{%site}}',
            'id',
            'RESTRICT'
        );
    }

    /**
     * {@inheritdoc}
     */
    public function safeDown()
    {
        // drops foreign key for table `{{%site}}`
        $this->dropForeignKey(
            '{{%fk-page-id_site}}',
            '{{%page}}'
        );

        // drops index for column `id_site`
        $this->dropIndex(
            '{{%idx-page-id_site}}',
            '{{%page}}'
        );

        $this->dropColumn('{{%page}}', 'id_site');
    }
}
